import java.util.Stack;
public class Solution{
    public static void main (String[] args) {
        int x = -123;
        System.out.println(new Solution().reverse(x));
    }

    public int reverse(int x) {
        if (x==0){
            return x;
        }
        
        String xStr = ""+x;
        int length = xStr.length();
        StringBuilder result = new StringBuilder();
        int symbol = 1;
        int i =0;
        if (xStr.startsWith("-")){
            symbol = -1;
            i =1;
        }
        Stack<Character> stack =new Stack<Character>();
        
        for( ;i < length; i++ ){
            stack.push(xStr.charAt(i));
        }
        while (!stack.isEmpty()){
            result.append(""+stack.pop());
        }
        long tmp = Long.parseLong(result.toString());
        if(tmp > Integer.MAX_VALUE || tmp < Integer.MIN_VALUE){
            return 0;
        }

        return symbol*(int)tmp;
    }
}